package com.mj.app.health.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mj.app.common_util.picasso.ImageLoader;
import com.mj.app.health.MyViewHolder;
import com.mj.app.health.R;
import com.mj.app.health.bean.ServiceBean;

import java.util.ArrayList;
import java.util.List;

/**
 * ========================================
 * *
 * title: ServiceAdapter
 * description:
 * *
 * Created by David Hogan on 2018/3/2.
 * ========================================
 */

public class ServiceAdapter extends BaseAdapter {

    private Context context;
    private List<ServiceBean> serviceBeans = new ArrayList<>();

    public void setServiceBeans(List<ServiceBean> serviceBeans){
        this.serviceBeans = serviceBeans;
        notifyDataSetChanged();
    }

    public ServiceAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return serviceBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return serviceBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null)
            convertView = LayoutInflater.from(context).inflate(R.layout.item_service, parent, false);

        ImageLoader.load(serviceBeans.get(position).getPaperImg(), (ImageView) MyViewHolder.getView(convertView, R.id.is_img));
        ((TextView) MyViewHolder.getView(convertView, R.id.is_txt)).setText(serviceBeans.get(position).getPaperTitle());

        return convertView;
    }
}
